﻿@{
    ViewBag.Title = "newindex";
}
@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <link href="~/Scripts/miniui/themes/default/medium-mode.css" rel="stylesheet" type="text/css" />      
}

<form id="form1" method="post">
            @Html.Partial("~/Views/Modular/Toolbars.cshtml")
        <div name="Base" title="颜色" style="height:100%;overflow:hidden;margin-top:25px;margin-left:50px">
            <table>
                <tr>
                <tr>
                    <td width="80px" height ="50px" align="right">
                        颜色编码：</td>
                    <td width="280px" height ="50px">
                        <input id="FNumber" name="FNumber" class="mini-textbox " style="width:280px;"  TabIndex="2" selectOnFocus="true"/>
                    </td>
                </tr>
                <tr>
                    <td width="80px" height ="50px" align="right">
                        颜色名称：</td>
                    <td width="280px" height ="50px">
                        <input id="FName" name="FName" class="mini-textbox " style="width:280px;"  TabIndex="2" selectOnFocus="true"/>
                    </td>
                </tr>
            </table>
            <br />
        </div>
    <input name="FItemID" class="mini-hidden" />
</form>

<script>
    function FormShown() {
        mini.parse();
    }

    //加载资料
    function SetInfoData(data) {
        if (data.action == "new") {
            //跨页面传递的数据对象，克隆后才可以安全使用
            mini.getbyName("FItemID").setValue('0');
            NewInfo();
        }
        else {
            $.post("GetColor", { json: "[{'FItemID':'" + data.FItemID + "','mSystemAppID':'" + parent.window.getSystemAppID() + "'}]" }, function (data) {
                var form = new mini.Form("form1");
                var mdata = mini.decode(data);
                mini.getbyName("FItemID").setValue(mdata.data[0].FItemID);
                form.setData(mdata.data[0]);
                mini.getbyName("FName").focus();
            });
        }
    }

    //新增资料
    function NewInfo() {
        mini.getbyName("FItemID").setValue("0");
        mini.getbyName("FName").setValue("");
        mini.getbyName("FName").focus();
    }

    //保存资料
    function SaveInfo() {
        if (mini.getbyName("FNumber").getValue() == '') {
            mini.alert("颜色编码不能为空");
            mini.getbyName("FNumber").focus();
            return;
        }
        if (mini.getbyName("FName").getValue() == '') {
            mini.alert("颜色名称不能为空");
            mini.getbyName("FName").focus();
            return;
        }
        if (mini.getbyName("FNumber").getValue().length != 2
            || isNaN(mini.getbyName("FNumber").getValue())) {
            mini.alert("颜色编码只能为2位数字");
            mini.getbyName("FNumber").focus();
            return;
        }
        mini.getbyName("SaveInfo").setEnabled(false);
        var form = new mini.Form("#form1");
        form.validate();
        if (form.isValid() == false) {
            mini.getbyName("SaveInfo").setEnabled(true);
            return;
        }
        var data = form.getData(true, false);

        var json = mini.encode(data);
        $.post("SaveColorInfo", { json: json, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                NewInfo();
            }
            else {
                mini.alert("异常 : " + ret.error);
            }
            mini.getbyName("SaveInfo").setEnabled(true);
        });
    }


</script>